<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:insert="common/person-pc/header::personHeadBar('收藏','/static/css/person/paper.css')">
<body class="centre" style="">
<!-- 头部 -->
<!-- 头部信息 -->
<div th:insert="common/person-pc/top::personTopBar(${resCategoryModel})"/>
<!-- END -->
<div class="ey-body-bg">
    <div class="ey-body">
        <div class="ey-container w1200">
            <!-- 侧边 -->
            <div th:insert="common/person-pc/right::rightBar(${show})"/>
            <!-- END -->
            <!-- 中部 -->
            <div class="ey-con fr">
                <div class="el-main main-bg">
                    <!-- 顶部导航栏 -->
                    <div class="column-title mb20">
                        <div class="column-name">我的收藏</div>
                    </div>
                    <!-- END -->
                    <div class="el-table el-table--fit el-table--enable-row-hover el-table--enable-row-transition mt20"
                         style="width: 100%;">
                        <table>
                            <thead>
                            <tr>
                                <th style="width:40px;">
                                    <div class="cell tc">
                                        <label class="checkbox-label release-checkbox">
                                            <span> &nbsp; </span>
                                            <input class="checkbox" type="checkbox" onclick="javascript:$('input[name*=ids]').prop('checked',this.checked);">
                                            <span class="check-mark"></span>
                                        </label>
                                    </div>
                                </th>
                                <th style="width:590px ;">
                                    <div class="cell">文章标题</div>
                                </th>
                                <th style="width: 200px;">
                                    <div class="cell tc">所属栏目</div>
                                </th>
                                <th style="width: 80px;">
                                    <div class="cell tc">操作</div>
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                                <th:block th:each="collections:${list}">
                                    <tr>
                                        <td>
                                            <div class="cell tc">
                                                <label class="checkbox-label release-checkbox">
                                                    <span> &nbsp; </span>
                                                    <input class="checkbox" type="checkbox" name="ids[]" th:value="${collections.id}">
                                                    <span class="check-mark"></span>
                                                </label>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="cell">
                                                <a href="javascript:void(0);" onclick="ArcUrl(this);" th:data-url="'/web/art-detail/'+${collections?.articleId}+'.html'">
                                                    <img th:src="${collections.titleImg}" style="max-height: 25px;max-width: 25px;" />
                                                    <span style="margin-left: 12px;" th:text="${collections.title}"></span>
                                                </a>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="cell tc" th:text="${collections.cateName}"></div>
                                        </td>
                                        <td>
                                            <div class="cell tc">
                                                <a href="javascript:void(0);" class="" style="margin-right: 0;" th:data-id="${collections.id}" onclick="DelData(this);">删除</a>
                                            </div>
                                        </td>
                                    </tr>
                                </th:block>
                            <tr>
                                <td>
                                    <label class="checkbox-label release-checkbox ml10">
                                        <span> &nbsp; </span>
                                        <input class="checkbox" type="checkbox"
                                               onclick="javascript:$('input[name*=ids]').prop('checked',this.checked);">
                                        <span class="check-mark"></span>
                                    </label>
                                </td>
                                <td>
                                    <a class="el-button el-button--default el-button--small" href="javascript:void(0);" onclick="BatchDelData(this, 'ids');">
                                        批量删除
                                    </a>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <script th:inline="javascript">
                        var count = [[${total}]];
                        var currentPage = [[${currentPage}]];
                        var requestUrl = [[${requestUrl}]];
                    </script>
                    <script type="text/javascript" th:src="@{'/static/Kz.layedit/Content/Layui-KnifeZ/layui.js'}"></script>
                    <script>
                        layui.use('laypage', function () {
                            var laypage = layui.laypage;
                            //执行一个laypage实例
                            laypage.render({
                                elem: 'pageId',
                                count: count,
                                curr: currentPage,  //当前页数
                                limit: 10,
                                theme: '#1E9FFF',
                                jump: function (obj, first) {
                                    if (!first) {
                                        location.href = requestUrl+"?pageNum=" + obj.curr;
                                    }
                                }
                            });
                        });
                    </script>
                    <div style="text-align: center;" >
                        <div id="pageId">
                        </div>
                        <div class="fytotal">共<span th:text="${total}"></span>条记录</div>
                    </div>
                </div>
                <!-- END -->
            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
    // 内容查看
    function ArcUrl(obj) {
        window.open($(obj).attr('data-url'));
    }

    // 删除单个收藏
    function DelData(obj) {
        console.log($(obj).attr('data-id'));
        layer.confirm('是否删除该收藏？', {
            title: false,
            btn: ['是', '否'] //按钮
        }, function () {
            layer_loading('正在处理');
            // 确定
            $.ajax({
                type: "POST",
                url: "/user/delcollectionArticle.html",
                data: {collectionId: $(obj).attr('data-id')},
                success: function (res) {
                    layer.closeAll();
                    if (res.rt == 1) {
                        layer.msg("删除成功！", {icon: 1});
                        window.location.reload();
                    }else if (res.rt == -1) {
                        showErrorMsg("未登录请先登录!");
                    } else {
                        showErrorAlert("删除失败！");
                    }
                },
                error: function (e) {
                    layer.closeAll();
                    showErrorAlert("网络异常,请稍后再试!");
                }
            });
        }, function (index) {
            layer.close(index);
        });
    }

    // 批量删除收藏
    function BatchDelData(obj, name) {
        var a = [];
        $('input[name^=' + name + ']').each(function (i, o) {
            if ($(o).is(':checked')) {
                a.push($(o).val());
            }
        })
        if (a.length == 0) {
            showErrorAlert('请至少选择一项！');
            return;
        }
       var collectionIds=a.toString();
        // 删除按钮
        layer.confirm('确认批量删除收藏？', {
            title: false,
            btn: ['确定', '取消'] //按钮
        }, function () {
            layer_loading('正在处理');
            $.ajax({
                type: "POST",
                url: "/user/delcollectionArticle.html",
                data: {collectionId: collectionIds},
                success: function (res) {
                    layer.closeAll();
                    if (res.rt == 1) {
                        layer.msg("删除成功！", {icon: 1});
                        window.location.reload();
                    }else if (res.rt == -1) {
                        showErrorMsg("未登录请先登录!");
                     } else {
                        showErrorAlert("删除失败！");
                    }
                },
                error: function (e) {
                    layer.closeAll();
                    showErrorAlert("网络异常,请稍后再试!");
                }
            });
        }, function (index) {
            layer.closeAll(index);
        });
    }
</script>
<!-- 底部 -->
<div class="ey-footer">
    <footer class="container">
        <p>Copyright © 2012-2018 资源基地 版权所有</p>
    </footer>
</div>
</body>
</html>
